import pandas as pd
import matplotlib.pyplot as plt

fp = open('./energy_data.csv')
line = fp.readline()
freq = []
watt = []
workload = []
#
while line:
    line = line.strip('\n')
    line = line.split('\t')
    f, e, w = line
    freq.append(int(f))
    watt.append(float(e))
    workload.append(float(w))
    line = fp.readline()

dict_x = {}
dict_y = {}
for i in range(len(freq)):
    f = freq[i]
    dict_x.setdefault(f, [])
    dict_y.setdefault(f, [])
    dict_x[f].append([workload[i], watt[i]])
    # dict_y[f].append(watt[i])

p = 1
# plt.figure(figsize=(6, 21))
# plt.figure(figsize=(3, 3))

label1 = []
label2 = []
key = 800
while True:
    data = dict_x[key]
    data = sorted(data)
    x = []
    y = []
    for d in data:
        x.append(d[0])
        y.append(d[1])
    plt.subplot(2, 1, 1)
    plt.axis([0, 70, 0, 200])
    plt.xlabel('workload')
    plt.ylabel('power (watt)')
    label1.append(key)
    plt.plot(x, y)
    data = dict_x[key + 100]
    data = sorted(data)
    x = []
    y = []
    for d in data:
        x.append(d[0])
        y.append(d[1])
    plt.subplot(2, 1, 2)
    plt.axis([0, 70, 0, 200])
    label2.append(key+100)
    plt.plot(x, y)
    key += 200
    if key > 2000:
        break

plt.subplot(2,1,1)
plt.title('800:200:2000')
# plt.legend(label1, loc=2)
plt.subplots_adjust(hspace=0.5)
plt.subplot(2,1,2)
plt.title('900:200:2100')
# plt.legend(label2, loc=2)
plt.xlabel('workload')
plt.ylabel('power (watt)')
plt.savefig('./result.png')